package com.gdth.bank.presenter;

import java.util.List;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import com.gdth.bank.model.DzCpKhXxDjModel;
import com.gdth.bank.view.DzCpKhXxDjView;
import com.gdth.database.bean.DzCpkhXxDj;
public class DzCpkhXxDjPresenter {
	private DzCpKhXxDjView  mDzCpKhXxDjView;
	private DzCpKhXxDjModel mDzCpKhXxDjModel;
	public int loadDzCpKhXx = 101;
	
	public DzCpkhXxDjPresenter(DzCpKhXxDjView mDzCpKhXxDjView) {
		
		this.mDzCpKhXxDjView = mDzCpKhXxDjView;
		mDzCpKhXxDjModel = new DzCpKhXxDjModel();
	}
	
	public void saveDzcpkhxxde(DzCpkhXxDj mDzCpkhXxDj){
		mDzCpKhXxDjModel.saveDzcpkhxxde(mDzCpkhXxDj)
			.subscribeOn(Schedulers.io())
			.unsubscribeOn(Schedulers.io())
			.observeOn(AndroidSchedulers.mainThread())
			.subscribe(new Subscriber<DzCpkhXxDj>(){

				@Override
				public void onCompleted() {
					// TODO Auto-generated method stub
					
				}

				@Override
				public void onError(Throwable arg0) {
					// TODO Auto-generated method stub
					mDzCpKhXxDjView.showMessage("保存失败");
				}

				@Override
				public void onNext(DzCpkhXxDj arg0) {
					// TODO Auto-generated method stub
				}
				
			});
	}
	
	public void getAllDzcpkhxxde(String val){
		mDzCpKhXxDjModel.getAllDzcpkhxxde(val)
		.subscribeOn(Schedulers.io())
		.unsubscribeOn(Schedulers.io())
		.observeOn(AndroidSchedulers.mainThread())
		.subscribe(new Subscriber<List<DzCpkhXxDj>>(){

			@Override
			public void onCompleted() {
				// TODO Auto-generated method stub
				mDzCpKhXxDjView.hideProgressDialog();
			}

			@Override
			public void onError(Throwable arg0) {
				// TODO Auto-generated method stub
				mDzCpKhXxDjView.showMessage("获取失败");
			}

			@Override
			public void onNext(List<DzCpkhXxDj> arg0) {
				// TODO Auto-generated method stub
			  mDzCpKhXxDjView.updateList(arg0);
			   
			}});
	}
	public void getDzcpkhxxde(String uuid){
		mDzCpKhXxDjModel.getDzcpkhxxde(uuid)
		.subscribeOn(Schedulers.io())
		.unsubscribeOn(Schedulers.io())
		.observeOn(AndroidSchedulers.mainThread())
		.subscribe(new Subscriber<List<DzCpkhXxDj>>(){

			@Override
			public void onCompleted() {
				// TODO Auto-generated method stub
				mDzCpKhXxDjView.hideProgressDialog();
			}

			@Override
			public void onError(Throwable arg0) {
				// TODO Auto-generated method stub
				mDzCpKhXxDjView.showMessage("获取失败");
			}

			@Override
			public void onNext(List<DzCpkhXxDj> arg0) {
				// TODO Auto-generated method stub
			  if (arg0 != null){
				  mDzCpKhXxDjView.updateView(loadDzCpKhXx, arg0);
				}
			}});
	}
    
    
}
